ARCH:=$(shell getconf LONG_BIT)

#Directories
WKSPCDIR=$(HOME)/workspace
SRCDIR=$(WKSPCDIR)/clique-projection/src/class
MAINDIR=$(WKSPCDIR)/clique-projection/src/main
STABDIR=$(WKSPCDIR)/clique-projection/src/stab
COLORDIR=$(WKSPCDIR)/clique-projection/src/color
LIBDIR=$(WKSPCDIR)/clique-projection/lib/$(ARCH)
BINDIR=$(WKSPCDIR)/clique-projection/bin/$(ARCH)
CPLEXDIR=/opt/ibm/ILOG/CPLEX_Studio125
CPLEXINCDIR=$(CPLEXDIR)/cplex/include
CONCERTINCDIR=$(CPLEXDIR)/concert/include
ifeq ($(ARCH),64)
	CPLEXLINKDIR=$(CPLEXDIR)/cplex/lib/x86-64_sles10_4.1/static_pic
	CONCERTLINKDIR=$(CPLEXDIR)/concert/lib/x86-64_sles10_4.1/static_pic
else
	CPLEXLINKDIR=$(CPLEXDIR)/cplex/lib/x86_sles10_4.1/static_pic
	CONCERTLINKDIR=$(CPLEXDIR)/concert/lib/x86_sles10_4.1/static_pic
endif

#Classes
VERTEXSET=VertexSet
GRAFO=Grafo
PROYECTABLE=Proyectable
DESIG=Desigualdad
SOLUC=Solucion
SOLVER=StabSolver
RDCLIQUER=RDCliquer
SEPARATOR=Separator

# ---------------------------------------------------------------------
# Compiler options 
# ---------------------------------------------------------------------

COMPILER= g++ -std=c++11
COPT=-m$(ARCH) -O -fPIC -fexceptions -DNDEBUG -DIL_STD -DILOSTRICTPOD
CFLAGS = -I$(SRCDIR) -I$(CPLEXINCDIR) -I$(CONCERTINCDIR)
LINKFLAGS = -L$(CPLEXLINKDIR) -lilocplex -lcplex -L$(CONCERTLINKDIR) -lconcert -lpthread -lm

# ---------------------------------------------------------------------
# Entries
# ---------------------------------------------------------------------

# Build a list of the object files to create, based on the .cpps we find
SRCS = $(wildcard $(SRCDIR)/*.cpp)
STABSRCS = $(wildcard $(STABDIR)/*.cpp)
COLORSRCS = $(wildcard $(COLORDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(LIBDIR)/%.o,$(SRCS))
CLASES = $(patsubst $(SRCDIR)/%.cpp,%.class,$(SRCS))
STABOBJS = $(patsubst $(STABDIR)/%.cpp,$(LIBDIR)/%.o,$(STABSRCS))
STABCLASES = $(patsubst $(STABDIR)/%.cpp,%.class,$(STABSRCS))
COLOROBJS = $(patsubst $(COLORDIR)/%.cpp,$(LIBDIR)/%.o,$(COLORSRCS))
COLORCLASES = $(patsubst $(COLORDIR)/%.cpp,%.class,$(COLORSRCS))

$(LIBDIR)/%.o: $(SRCDIR)/%.cpp $(SRCDIR)/%.h
	$(COMPILER) ${COPT} ${CFLAGS} -c $(patsubst $(LIBDIR)/%.o,$(SRCDIR)/%.cpp,$@) -o $@

Main%: $(OBJS) $(MAINDIR)/Main%.cpp
	$(COMPILER) $^ ${COPT} ${CFLAGS} ${LINKFLAGS} -o $(patsubst Main%,$(BINDIR)/%,$@)

%.class:
	$(COMPILER) ${COPT} ${CFLAGS} ${LINKFLAGS} -c $(patsubst %.class,$(SRCDIR)/%.cpp,$@) -o $(patsubst %.class,$(LIBDIR)/%.o,$@)

all: $(CLASES) $(STABCLASES) $(COLORCLASES)
	make MainStab
	make MainColor
	
$(SRCDIR)/Main.h:
